package com.ledim.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.ledim.adapter.base.LedimBaseListAdapter;
import com.ledim.bean.CoinDetailBean;
import com.letv.android.young.client.R;
import java.util.List;

/**
 * Created by qjq on 16/9/14 14:05.
 */
public class GoldDetailAdapter extends LedimBaseListAdapter<CoinDetailBean> {

    public GoldDetailAdapter(Context context, List<CoinDetailBean> data) {
        super(context);
        setDatas(data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.gold_detail_first_item, null);
            holder.mCoinNumber = (TextView) convertView.findViewById(R.id.tv_coin_number);
            holder.mCoinDate = (TextView) convertView.findViewById(R.id.tv_coin_date);
            holder.mCoinUser = (TextView) convertView.findViewById(R.id.tv_coin_user);
            holder.mItemBg = (LinearLayout) convertView.findViewById(R.id.ll_item_bg);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        CoinDetailBean coinDetailBean = getItem(position);
        //日期
        holder.mCoinDate.setText(coinDetailBean.op_date);

        //类型判断
        if (coinDetailBean.type == 1) {
            holder.mCoinUser.setText("签到");
        } else if (coinDetailBean.type == 2) {
            if (coinDetailBean.status == 0) {
                holder.mCoinUser.setText("其他");
            } else if (coinDetailBean.status == 1) {
                holder.mCoinUser.setText("放映厅收入");
            } else if (coinDetailBean.status == 2) {
                holder.mCoinUser.setText("打赏给房主");
            }
        } else if (coinDetailBean.type == 3) {
            holder.mCoinUser.setText("连续签到");
        } else if (coinDetailBean.type == 4) {
            holder.mCoinUser.setText("首次登录");
        } else if (coinDetailBean.type == 5) {
            holder.mCoinUser.setText("首次创建放映厅");
        }

        if (coinDetailBean.type == 2 && coinDetailBean.status == 2) {
            //为负数
            holder.mCoinNumber.setTextColor(Color.parseColor("#FA5F5F"));
            holder.mCoinNumber.setText("- " + Math.abs(coinDetailBean.coin) + "发");
        } else {
            holder.mCoinNumber.setTextColor(Color.parseColor("#333333"));
            holder.mCoinNumber.setText("+ " + coinDetailBean.coin + "发");
        }

        //背景判断
        if (getCount() == 1) {
            holder.mItemBg.setBackgroundResource(R.drawable.mygold_list_one_item);
        } else if (getCount() == 2) {
            if (position == 0) {
                holder.mItemBg.setBackgroundResource(R.drawable.mygold_list_two_one);
            } else {
                holder.mItemBg.setBackgroundResource(R.drawable.mygold_list_end_item_bg);
            }
        } else {
            if (position == 0) {
                holder.mItemBg.setBackgroundResource(R.drawable.mygold_list_two_one);
            } else if (position >= 1 && position < (getCount() - 1)) {
                holder.mItemBg.setBackgroundResource(R.drawable.mygold_list_three_item_bg);
            } else {
                holder.mItemBg.setBackgroundResource(R.drawable.mygold_list_end_item_bg);
            }
        }

        return convertView;
    }

    static class ViewHolder {

        TextView mCoinNumber;
        TextView mCoinDate;
        TextView mCoinUser;
        LinearLayout mItemBg;
    }
}
